#ifndef _SPI_H_
#define _SPI_H_

#include "../../bit/bit.h"
#include "../../bitpointer/BitPointer.h"
#include "../../clock/Clock.h"
#include "../../edgewatcher/EdgeWatcher.h"
#include "../../bitshifter/BitShifter.h"


class Spi
{
	private:
		unsigned char transferCount; // has to be between 0-8.
		unsigned char start; 
		unsigned char slaveOrMaster; //master is 1 , slave is 0;

		EdgeWatcher watcher;

		BitPointer SS;
		Clock SCK;
		BitShifter MISO;
		BitShifter MOSI;

	//clock polarity and phase
	unsigned char CPOL;
	unsigned char CPHA;

	public:
		Spi();
		Spi(BitPointer sel, Clock clk, BitPointer in, BitPointer out,
			unsigned char polarity, unsigned char phase,
			unsigned char master);

		void sendBit();
		void receiveBit();

		void sampleBit();
		void setInput(unsigned char value);
		unsigned char getInput();
		unsigned char getOutput();
		void select();
		void deselect();

		virtual void run();




};




#endif
